package com.hghivln.blog.controller;


import com.hghivln.blog.common.annotation.IgnoreLog;
import com.hghivln.blog.common.lang.Result;
import com.hghivln.blog.entity.Log;
import com.hghivln.blog.pojo.dto.LogDto;
import com.hghivln.blog.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统日志 前端控制器
 * </p>
 *
 * @author hghivln
 * @since 2021-08-29
 */
@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService LogService;

    /**
     * 分页查询
     */
    @PostMapping("getByPage")
    @IgnoreLog
    public Result<?> loadAllLog(@RequestBody LogDto logDto) {
        return LogService.loadAllLog(logDto);
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/get/{id}")
    @IgnoreLog
    public Result<Log> get(@PathVariable Long id) {
        Log log = LogService.getById(id);
        return new Result<>(log);
    }

    /**
     * 根据id删除
     */
    @DeleteMapping("delete/{id}")
    @IgnoreLog
    public Result<?> delete(@PathVariable Long id) {
        LogService.removeById(id);
        return new Result<>("删除成功!");
    }
}
